package cn.lynu.study.practice11_30;

class MyRunnable2 implements Runnable{
	public int var1;
	@Override
	public void run() {
		while(true) {
			synchronized(this) {
				String threadName = Thread.currentThread().getName();
				System.out.println(threadName+"var1="+var1);
				var1++;
				try {Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();}
			}
				
			}
		}
	}

public class Test02 {
	public static void main(String[] args) {
		MyRunnable2 myRunnable=new MyRunnable2();
		Thread t1=new Thread(myRunnable,"߳1");
		Thread t2=new Thread(myRunnable,"߳2");
		Thread t3=new Thread(myRunnable,"߳3");
		t1.start();
		t2.start();
		t3.start();
	}
}
